package mo.offer_version2;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class L57_2 {

    public int[][] findContinuousSequence(int target) {
        List<int[]> list = new ArrayList<>();
        int left = 1;
        int right = 2;
        int sum = left + right;

        while (right < target) {
            if (sum == target) {
                int[] tmp = new int[right-left+1];
                for (int i = left; i <= right; i++) {
                    tmp[i-left] = i;
                }
                list.add(tmp);
                sum -= left;
                left++;
                right++;
                sum += right;
            } else if (sum < target) {
                right++;
                sum += right;
            } else {
                sum -= left;
                left++;
            }
        }
        int[][] res = new int[list.size()][];
        for (int i = 0; i < list.size(); i++) {
            res[i] = list.get(i);
        }
        return res;
    }

    public static void main(String[] args) {
        L57_2 test = new L57_2();
        System.out.println(Arrays.deepToString(test.findContinuousSequence(15)));
    }

}
